package com.flying.invest.base.spider;

import com.alibaba.fastjson.JSONObject;
import com.flying.common.http.JsonHttpUtils;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.model.ModelFactory;
import com.flying.framework.service.AbstractService;

@Service(value="CurrencySpider", desc="东方财富价格抓取")
public class CurrencyRateSpider extends AbstractService {
	public CurrencyRate fetch(@Param(value=CurrencyRate.CODE,   required=true,   maxlength=3,	desc="币种代码" )String code) throws Exception {
		JSONObject jo = JsonHttpUtils.get(this.getUrl(code));
		Double rate = jo.getJSONObject("data").getDouble("f46") / 10000;
		return ModelFactory.create(CurrencyRate.class, CurrencyRate.CODE, code, CurrencyRate.RATE, rate);
	}
	private String getUrl(String code) {
		return "http://push2.eastmoney.com/api/qt/stock/get?secid=120."+code+"CNYC&fields=f57,f58,f59,f107,f43,f44,f45,f46,f60,f152,f169,f170,f119,f120,f121,f122,f169,f170,f174,f175&invt=2&cb=";
	}
}
